﻿using System.Collections.Generic;
using System.Linq;
using MyFinanceManager.Objects;

namespace MyFinanceManager
{
    public class Repository
    {
        private List<CatInfo> catInfos;

        public List<CatInfo> CatInfos
        {
            get
            {
                return catInfos;
            }
        }

        private Repository(string filename)
        {
            this.catInfos = Helper.Load(filename);
        }


        #region Singleton Pattern
        private static Repository repositoryCenterIn;

        public static Repository RepositoryCenterIn
        {
            get
            {
                if (repositoryCenterIn == null)
                    repositoryCenterIn = new Repository(Filenames.FilenameCategoryIn);
                return repositoryCenterIn;
            }
        }

        private static Repository repositoryCenterEx;

        public static Repository RepositoryCenterEx
        {
            get
            {
                if (repositoryCenterEx == null)
                    repositoryCenterEx = new Repository(Filenames.FilenameCategoryEx);
                return repositoryCenterEx;
            }
        }
        #endregion


        public bool HasSubCat(int catId)
        {
            var ergebnis = Helper.GetCountFromCategory(catId, this.catInfos);
            return ergebnis > 0;
        }
    }
}
